import 'package:flutter_app/bean/article_entity.dart';
import 'package:flutter_app/network/Api.dart';
import 'package:flutter_app/network/ResultData.dart';
import 'package:flutter_app/ui/main/main_logic.dart';
import 'package:flutter_app/utils/toast_utils.dart';
import 'package:get/get.dart';

import 'msg_detail_state.dart';

class MsgDetailLogic extends GetxController {
  final MsgDetailState state = MsgDetailState();
  final mainLogic = Get.find<MainLogic>();


  late String id;

  @override
  void onInit() {
    super.onInit();
    id = Get.arguments;
  }

  @override
  void onReady() {
    super.onReady();
    postArticle(id);
  }

  ///获取内容详情
  Future<void> postArticle(String id) async {
    Map<String, dynamic> param = {
      "id": id,
    };
    ResultData resultData = await Api.postArticle(param);
    if (resultData.isSuccess) {
      state.articleEntity = ArticleEntity.fromJson(resultData.data['data']);
      update();
    } else {
      toast.show(resultData.data["message"]);
    }
  }

  @override
  void onClose() {
    super.onClose();
  }
}
